import csv
import string
import sys
import time
import logging
import struct
import threading
import datetime, calendar

f = open('/home/cbe/Downloads/nyt2011_10_14a.csv', 'rb')
data = csv.reader(f)
headers = next(data)
ids = {}
new = '_'
for header in headers:
    header = string.replace(header, '.', '/')
    header = string.replace(header, ':', '/')
    header = string.replace(header, 'OCC/UNOCC', 'OCC_UNOCC')
    header = string.replace(header, 'HEAT/COOL', 'HEAT_COOL')
    header = string.replace(header, 'DSP/N', 'DSP_N')
    header = string.replace(header, 'DSP/S', 'DSP_S')    
    header = string.replace(header, 'CRA/DIFF', 'CRA_DIFF')
    header = string.replace(header, 'TZ/SP', 'TZ_SP')
    header = string.replace(header, 'TS/SP', 'TS_SP')
    header = header.replace('CRA/SP', 'CRA_SP')
    if str.count(header, '/') > 3:
        li = header.rsplit('/',1)
        header = new.join(li)
    
keyOn = set(['OCC','COOL','ON','START','ENABLED','OPEN'])
keyOff = set(['UNOCC','HEAT','OFF','STOP','DISABLED','CLOSED','DISABL'])
for row in data:
    datetime = row[0] + ' ' + row[1]
    smaptime = calendar.timegm(time.strptime(datetime, '%m/%d/%Y %H:%M:%S')) + 3600*7
    for i in xrange(2,len(row)-10):
        if len(keyOn.intersection(set([row[i]]))) != 0:
            row[i] = 1
        if len(keyOff.intersection(set([row[i]]))) != 0:
            row[i] = 0
        print row[i]
    exit()
f.close()    